use metadata_extractor::DefaultMetadataExtractor;
use model_graph_types::{
    database::{ConnectorProtocol, DataSource, DatabaseType},
    extractor::{ExtractFromDatabaseOption, MetadataExtractor, MetadataPackage},
    modeling::{Class, ModelingReader, ModelingWriter},
};

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .init();
    tracing::info!("RRAI 启动...");

    let extractor = DefaultMetadataExtractor {};

    let sqlite_data_source = DataSource {
        database_type: DatabaseType::SQLite,
        protocol: ConnectorProtocol::SQLite,
        url: String::from("sqlite:/Users/suhs/rrg01/rrg01.sqlite"),
        username: None,
        password: None,
        options: None,
    };

    let mysql_data_source = DataSource {
        database_type: DatabaseType::MySQL,
        protocol: ConnectorProtocol::MySQL,
        url: String::from("mysql://root:6e4a1a8993be1628@39.106.1.82:8306/rrai_prod"),
        username: None,
        password: None,
        options: None,
    };

    let dist_data_source = DataSource {
        database_type: DatabaseType::SQLite,
        protocol: ConnectorProtocol::SQLite,
        url: String::from("sqlite:/Users/suhs/rrg01/rrg01.sqlite"),
        username: None,
        password: None,
        options: None,
    };

    // let res = extractor
    //     .extract_from_database(&sqlite_data_source, ExtractFromDatabaseOption {})
    //     .await;

    // match res {
    //     Ok(result) => {
    //         // tracing::debug!("!!!!!!{:?}", result);
    //         //写数据到数据库中
    //         let writer = modeling_mini::sqlite::MiniSqliteModelingWriter {};
    //         writer
    //             .write(&result.model_package, &sqlite_data_source)
    //             .await;
    //     }
    //     Err(err) => tracing::debug!("===-----{:?}", err),
    // }

    // let res = extractor
    //     .extract_from_database(&mysql_data_source, ExtractFromDatabaseOption {})
    //     .await;

    // match res {
    //     Ok(result) => {
    //         tracing::debug!("==={:?}", result);
    //         //写数据到数据库中
    //         let writer = modeling_mini::sqlite::MiniSqliteModelingWriter {};
    //         writer
    //             .write(&result.model_package, &sqlite_data_source)
    //             .await;
    //     }
    //     Err(err) => tracing::debug!("{:?}", err),
    // }

    //写数据到数据库中
    let reader = modeling_mini::sqlite::MiniSqliteModelingReader {};
    let res = reader.read(&sqlite_data_source).await;

    match res {
        Ok(result) => {
            tracing::debug!("==={:?}", result);
        }
        Err(err) => tracing::debug!("{:?}", err),
    }
}
